home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / dejagnu / runtest.exp < prev    next >
Text File  |  1993-05-26  |  19KB  |  632 lines

  1. # Test Framework Driver
  2. #   Copyright (C) 1988, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  15.  
  16. # Please email any bugs, comments, and/or additions to this file to:
  17. # bug-dejagnu@prep.ai.mit.edu
  18.  
  19. # This file was written by Rob Savoye. (rob@cygnus.com)
  20.     
  21. set frame_version    1.0.1
  22.  
  23. #
  24. # trap some signals so we know whats happening. These definitions are only
  25. # temporary until we read in the library stuff
  26. #
  27. trap { send_user "\nterminated\n";             exit 1 } SIGTERM
  28. trap { send_user "\ninterrupted by user\n";    exit 1 } SIGINT
  29. trap { send_user "\nsegmentation violation\n"; exit 1 } SIGSEGV
  30. trap { send_user "\nsigquit\n";                exit 1 } SIGQUIT
  31.  
  32. #
  33. # initialize a few global variables used by all tests
  34. #
  35. set do_a_diff    0        ;# flag enabling diff of summary logs
  36. set mail_logs   0        ;# flag for mailing of summary and diff logs
  37. set psum_file   "latest"    ;# file name of previous summary to diff against
  38. set passcnt    0        ;# number of testcases that passed
  39. set failcnt    0        ;# number of testcases that failed
  40. set xfailcnt    0        ;# number of testcases expected to fail which did
  41. set xpasscnt    0        ;# number of testcases that passed unexpectedly
  42. set exit_status    0        ;# exit code returned by this program
  43. set xfail_flag  0
  44. set xfail_prms    0
  45. set sum_file    ""        ;# name of the file that contains the summary log
  46. set base_dir    ""        ;# the current working directory
  47. set logname     ""        ;# the users login name
  48. set prms_id    0
  49. set bug_id    0
  50. set test_name    ""        ;# name of the test driver to be run
  51. set dir        ""        ;# temp variable for directory names
  52. set srcdir      "."        ;# source directory containing the test suite
  53. set ignoretests ""        ;# list of tests to not execute
  54. set target      ""        ;# type of architecture to run tests on
  55. set host        ""        ;# type of architecture to run tests from
  56. set objdir    "."        ;# directory where test case binaries live
  57. set target_triplet "native"    ;# canonical triplet target name
  58. set makevars    ""
  59.  
  60. #
  61. # some convenience abbreviations
  62. #
  63. if ![info exists hex] then {
  64.     set hex "0x\[0-9A-Fa-f\]+"
  65. }
  66. if ![info exists decimal] then {
  67.     set decimal "\[0-9\]+"
  68. }
  69.  
  70. #
  71. # set the base dir (current working directory)
  72. #
  73. if [string match "" $base_dir] then {
  74.     set base_dir [exec pwd]
  75.     if [string match "*Command not found*" $base_dir] then {
  76.     if [info exists env(PWD)] then {
  77.         set base_dir $env(PWD)
  78.     } else {
  79.         set base_dir ""
  80.     }
  81.     if [string match "" $base_dir] then {
  82.         puts stderr "ERROR: couldn't get the current directory" ; exit -1
  83.         }
  84.     }
  85. }
  86.  
  87. #
  88. # These are tested in case they are not initialized in site.exp. They are
  89. # tested here instead of the init module so they can be overridden by command
  90. # line options.
  91. #
  92. if ![info exists all_flag] then {
  93.     set all_flag    0
  94. }
  95. if ![info exists binpath] then {
  96.     set binpath    ""
  97. }
  98. if ![info exists debug] then {
  99.     set debug  0
  100. }
  101. if ![info exists options] then {
  102.     set options    ""
  103. }
  104. if ![info exists outdir] then {
  105.     set outdir      "."
  106. }
  107. if ![info exists reboot] then {
  108.     set reboot    1
  109. }
  110. if ![info exists runtests] then {
  111.     set runtests    ""
  112. }
  113. if ![info exists tracelevel] then {
  114.     set tracelevel  0
  115. }
  116. if ![info exists verbose] then {
  117.     set verbose    0
  118. }
  119.  
  120. #
  121. # get the users login name
  122. #
  123. if [string match "" $logname] then {
  124.     set logname [exec whoami]
  125.     if [string match "*Command not found*" $logname] then {
  126.     set logname [exec who am i]
  127.     if [string match "*Command not found*" $logname] then {    
  128.         send_user "ERROR: couldn't get the users login name\n" ; exit -1
  129.     } else {
  130.         set logname [lindex [split $logname " !"] 1]
  131.     }
  132.     }
  133. }
  134.  
  135. #
  136. # parse configuration args so the config file can get loaded. Otherwise 
  137. # command line options can't override the settings.
  138. #
  139. set match 0
  140. set argc [ llength $argv ]
  141. for { set i 1 } { $i < $argc } { incr i } {
  142.     global target_triplet
  143.     global host_triplet
  144.     set sub_arg [ lindex $argv $i ]
  145.     case $sub_arg in {
  146.  
  147.     {"[-+]ho*" "[-+][-+]ho*"} {            # (--host) the host configuration
  148.         incr i
  149.         set host_triplet [lindex $argv $i]
  150.         continue
  151.     }
  152.  
  153.     {"[-+]ta*" "[-+][-+]ta*"} {            # (--target) the target configuration
  154.         incr i
  155.         set target_triplet [lindex $argv $i]
  156.           # override local site file and load the configuration of a different target
  157.     }
  158.     }
  159. }
  160.  
  161. #
  162. # find where the config file is. ALL are sourced in order. The order is
  163. # first see if one is installed. Then look for for a parallel "dejagnu" 
  164. # directory up one or two directories. Finally source one in the current
  165. # dir if it exists.
  166. #
  167. set execpath     "[file dirname [lindex $argv 0]]"
  168. set libdir        [file dirname $execpath]/dejagnu
  169.  
  170. if [string match "." $objdir] then {
  171.     set objdir $base_dir
  172. }
  173.  
  174. foreach dir "$libdir/$target_triplet [file dirname $objdir]/dejagnu [file dirname [file dirname $objdir]]/dejagnu ." {
  175.     #send_user "Looking for config file $dir/site.exp\n"
  176.     if [file exists $dir/site.exp] then {
  177.     #send_user "Sourcing config file $dir/site.exp\n"
  178.     catch "source $dir/site.exp" tmp
  179.     }
  180. }
  181.  
  182. #
  183. # parse the command line arguments
  184. #
  185. set match 0
  186. set argc [ llength $argv ]
  187. for { set i 1 } { $i < $argc } { incr i } {
  188.     set sub_arg [ lindex $argv $i ]
  189.     case $sub_arg in {
  190.  
  191.     {"[-+]ho*" "[-+][-+]ho*"} {            # (--host) the host configuration
  192.         incr i
  193.         if $verbose>1 then { send_user "The host is now $host_triplet\n" }
  194.         continue
  195.     }
  196.  
  197.     {"[-+]ta*" "[-+][-+]ta*"} {            # (--target) the target configuration
  198.         incr i
  199.         if $verbose>1 then { send_user "The target is now $target_triplet\n" }
  200.         continue
  201.     }
  202.  
  203.     {"[-+]a*" "[-+][-+]a*"} {            # (--all) print all test output to screen
  204.         set all_flag 1
  205.         if $verbose>1 then { send_user "Print all test output to screen\n" }
  206.         continue
  207.     }
  208.  
  209.         {"[-+]b*" "[-+][-+]b*"} {            # (--baud) the baud to use for a serial line
  210.         incr i
  211.         set baud [lindex $argv $i]
  212.         if $verbose>1 then { send_user "The baud rate is now $baud\n" }
  213.         continue
  214.     }
  215.  
  216.     {"[-+]co*" "[-+][-+]co*"} {            # (--connect) the connection mode to use
  217.         incr i
  218.         set connectmode [lindex $argv $i]
  219.         if $verbose>1 then { send_user "Comm method is $connectmode\n" }
  220.         continue
  221.     }
  222.  
  223.     {"[-+]de*" "[-+][-+]de*"} {            # (--debug) expect internal debugging
  224.         catch "exec rm ./dbg.log"
  225.         debug -f dbg.log 0
  226.         if $verbose>1 then { send_user "Expect Debugging is ON \n" }
  227.         continue
  228.     }
  229.  
  230.     {"[-+]di*" "[-+][-+]di*"} {        # (--diff) diff the summary files
  231.         send_user "Sorry, --diff unimplemented\n"
  232.         #set do_a_diff 1
  233.         #incr i
  234.         #set psum_file [lindex $argv $i]
  235.         #if $verbose>1 then { send_user "Diff summary files when done\n" }
  236.         continue
  237.     }
  238.  
  239.     {"[-+]m*" "[-+][-+]m*"} {            # (--mail) mail the output
  240.         incr i
  241.         set mailing_list [lindex $argv $i]
  242.             set mail_logs 1
  243.         if $verbose>1 then { send_user "Mail results to $mailing_list\n" }
  244.         continue
  245.     }
  246.  
  247.     {"[-+]no*" "[-+][-+]no*"} {            # (--noreboot) Don't reboot the target
  248.         set reboot 0
  249.         if $verbose>1 then { send_user "Won't reboot the target\n" }
  250.         continue
  251.     }
  252.  
  253.     {"[-+]ob*" "[-+][-+]ob*"} {            # (--objdir) where the test case object code lives
  254.         incr i
  255.         set objdir [lindex $argv $i]
  256.         if $verbose>1 then { send_user "Using test binaries in $objdir\n" }
  257.         continue
  258.     }
  259.  
  260.     {"[-+]ou*" "[-+][-+]ou*"} {            # (--outdir) where to put the output files
  261.         incr i
  262.         set outdir [lindex $argv $i]
  263.         if $verbose>1 then { send_user "Test output put in $outdir\n" }
  264.         continue
  265.     }
  266.  
  267.     {"[-+]ru*" "[-+][-+]ru*"} {            #  (--runtest) specify test names to run
  268.         incr i
  269.         set runtests [lindex $argv $i]
  270.         if $verbose>1 then { send_user "Running only tests $runtests\n" }
  271.         continue
  272.     }
  273.  
  274.     {"[-+]i*" "[-+][-+]i*"} {            #  (--ignore) specify test names to exclude
  275.         incr i
  276.         set ignoretests [lindex $argv $i]
  277.         if $verbose>1 then { send_user "Ignoring test $ignoretests\n" }
  278.         continue
  279.     }
  280.  
  281.     {"[-+]sr*" "[-+][-+]sr*"} {            # (--srcdir) where the testsuite source code lives
  282.         incr i
  283.         set srcdir [lindex $argv $i]
  284.         if $verbose>1 then { send_user "Using test sources in $srcdir\n" }
  285.         continue
  286.     }
  287.  
  288.     {"[-+]st*" "[-+][-+]st*"} {            # (--strace) expect trace level
  289.         incr i
  290.         set tracelevel [ lindex $argv $i ]
  291.         strace $tracelevel
  292.         if $verbose>1 then { send_user "Source Trace level is now $tracelevel\n" }
  293.         continue
  294.     }
  295.  
  296.     {"[-+]n*" "[-+][-+]n*"} {            # (--name) the target's name
  297.         incr i
  298.         set targetname [lindex $argv $i]
  299.         if $verbose>1 then { send_user "Testing target $targetname\n" }
  300.         continue
  301.     }
  302.  
  303.     {"[-+]to*" "[-+][-+]to*"} {            # (--tool) specify tool name
  304.         incr i
  305.         set tool [lindex $argv $i]
  306.         if $verbose>1 then { send_user "Testing $tool\n" }
  307.         continue
  308.         }
  309.  
  310.     {"*[-+]V*" "*[-+]vers*"} {            # (--version) version numbers
  311.         send_user "Expect version is\t$expect_version\n"
  312.         send_user "Tcl version is\t\t[ info tclversion ]\n"
  313.         send_user "Framework version is\t$frame_version\n"
  314.         continue
  315.     }
  316.  
  317.     "[A-Z]*=*" {                    # process makefile style args like CC=gcc, etc...
  318.         set tmp [split $sub_arg "="]
  319.         set [lindex $tmp 0] [lindex $tmp 1]
  320.         if $verbose>1 then {
  321.                send_user "[lindex $tmp 0] is now [lindex $tmp 1]\n"
  322.             }
  323.         append makevars "set [lindex $tmp 0] [lindex $tmp 1];"
  324.         unset tmp
  325.         continue
  326.     }
  327.  
  328.     {"[-+]v*" "[-+][-+]v*" "*[-+]verb*"} {        # (--verbose) verbose output
  329.         incr verbose
  330.         if $verbose then { send_user "Verbose is now at level $verbose\n" }
  331.         continue
  332.     }
  333.  
  334.     {"[-+]he*" "[-+][-+]he*"} {        # (--help) help text
  335.         send_user "USAGE: runtest \[options...\]\n"
  336.         send_user "\t--all (-a)\t\tPrint all test output to screen\n"
  337.         send_user "\t--baud (-b)\t\tThe baud rate\n"
  338.         send_user "\t--connect (-co)\t\[type\]\tThe type of connection to use\n"
  339.         send_user "\t--debug (-de)\t\tSet expect debugging ON\n"
  340.         send_user "\t--diff \[name\]\t\tRun diff between two test runs\n"
  341.         send_user "\t--help (-he)\t\tPrint help text\n"
  342.         send_user "\t--mail \[name(s)\]\tWho to mail the results to\n"
  343.         send_user "\t--noreboot \[name\]\tDon't reboot the target\n"
  344.             send_user "\t--objdir \[name\]\t\tThe test suite binary directory\n"
  345.         send_user "\t--outdir \[name\]\t\tThe directory to put logs in\n"
  346.         send_user "\t--runtest \[name(s)\]\tThe names of specific tests to run\n"
  347.         send_user "\t--ignore \[name(s)\]\tThe names of specific tests to ignore\n"
  348.         send_user "\t--srcdir \[name\]\t\tThe test suite source code directory\n"
  349.         send_user "\t--strace \[number\]\tSet expect tracing ON\n"
  350.         send_user "\t--name \[name\]\t\tThe hostname of the target board\n"
  351.         send_user "\t--target \[string\]\tThe canonical config name of the target board\n"
  352.         send_user "\t--host \[string\]\t\tThe canonical config name of the host machine\n"
  353.         send_user "\t--tool\[name(s)\]\t\tRun tests on these tools\n"
  354.         send_user "\t--verbose (-v)\t\tEmit verbose output\n"
  355.         send_user "\t--version (-V)\t\tEmit all version numbers\n"
  356.         send_user "\tMakefile style arguments can also be used, ex. CC=gcc\n\n"
  357.         exit 0    
  358.     }
  359.  
  360.     default {        # default
  361.         send_user "\nIllegal Argument \"$sub_arg\"\n"
  362.         send_user "try \"runtest --help\" for option list\n"
  363.         exit 0
  364.     }
  365.  
  366.     }
  367. }
  368.  
  369. #
  370. # check for a few crucial variables
  371. #
  372. if ![info exists tool] then {
  373.     send_error "ERROR: No tool specified, use the --tool option\n"
  374.     exit 1
  375. }
  376.  
  377. if ![info exists host_triplet] then {
  378.     send_error "ERROR: No host configuration. Check the config file.\n"
  379.     exit 1
  380. }
  381.  
  382. if ![info exists target_triplet] then {
  383.     send_error "ERROR: No target configuration. Check the config file.\n"
  384.     exit 1
  385. }
  386.  
  387. #
  388. # initialize a few Tcl variables to something other than their default
  389. #
  390. if $verbose>2 then {
  391.     log_user 1
  392. } else {
  393.  
  394.     log_user 0
  395. }
  396. set timeout     10
  397.  
  398. #
  399. # load_lib --     loads a library by sourcing it. If there a multiple files with
  400. #                 the same name, they all get sourced in order. The order is first
  401. #           look in the install dir, then in a parallel dir in the source tree,
  402. #        (up one or two levels), then in the current dir.
  403. #
  404. proc load_lib { file } {
  405.     global verbose
  406.     global libdir
  407.     global srcdir
  408.     global base_dir
  409.     global execpath
  410.     global tool
  411.  
  412.     set found 0
  413.     set tmp   ""
  414.     foreach dir "$libdir $libdir/lib [file dirname [file dirname $srcdir]]/dejagnu/lib $srcdir/lib ." {
  415.     if $verbose>2 then {
  416.         send_user "Looking for $dir/$file\n"
  417.     }
  418.     if [file exists $dir/$file] then {
  419.         if $verbose>2 then {
  420.         send_user "Loading $dir/$file\n"
  421.         }
  422.         catch "source $dir/$file" tmp
  423.         if ![string match "" $tmp] then {
  424.         send_user "ERROR: errors in library file $dir/$file\n$tmp\n"
  425.         exit 1
  426.         } else {
  427.         set found 1
  428.         }
  429.     }
  430.     }
  431.     if $found==0 then {
  432.     send_user "ERROR: Couldn't load $file.\n"
  433.     exit 1
  434.     }
  435.     unset found
  436.     unset tmp
  437. }
  438.  
  439. #
  440. # load the testing framework libraries
  441. #
  442. load_lib utils.exp
  443. load_lib framework.exp
  444.  
  445. #
  446. #
  447. # set target variables only if needed.
  448. #
  449. if ![isnative] then {
  450.     # MVME board running *Bug boot monitor
  451.     if [istarget "*-abug-*"] then {
  452.     if ![info exists targetname] then {
  453.         puts stderr "ERROR: Need a target name for the target board."
  454.         puts stderr "       Use the --target option\n"
  455.         exit 1
  456.     }
  457.     # the default connect program to use
  458.     if ![info exists connectmode] then {
  459.         set connectmode    "tip"
  460.         warning "Using default of $connectmode for target communication."
  461.         }
  462.     }
  463.     # any flavor of vxworks
  464.     if [istarget "*-*-vxworks"] then {
  465.     # the hostname of the target board
  466.     if ![info exists targetname] then {
  467.     puts stderr "ERROR: Need a target name for the vxworks board."
  468.     puts stderr "       Use the --target option\n"
  469.     exit 1
  470.     }
  471.     # the default connect program to use
  472.     if ![info exists connectmode] then {
  473.         set connectmode    "rlogin"
  474.         warning "Using default of $connectmode for target communication."
  475.         }        
  476.     }
  477. }
  478.  
  479. #
  480. # open log files
  481. #
  482. open_logs
  483. clone_output "Test Run By $logname on [exec date]"
  484. clone_output "Target is $target_triplet"
  485. clone_output "Host   is $host_triplet"
  486. clone_output "\n\t\t=== $tool tests ===\n"
  487.  
  488. #
  489. # go find the init file. A local copy is sourced if it is found,
  490. # otherwise the system default one is sourced instead
  491. #
  492. set tool_init $srcdir/config/${target_abbrev}
  493.  
  494. #
  495. # find the tool init file. This is in the config directory of the tool's
  496. # testsuite directory. These used to all be named $target_os-$tool.exp,
  497. # but as the $tool variable goes away, it's now just $target_os.exp.
  498. #
  499. if [ expr "[file exists ${tool_init}-${tool}.exp] + [file exists ${tool_init}-${tool}.exp] == 2"] then {
  500.     catch "source ${tool_init}-${tool}.exp" error
  501.     if ![string match "" $error] then {
  502.     send_user "ERROR: errors in tool init file ${tool_init}-${tool}.exp\n$error\n"
  503.     exit 1
  504.     }
  505.     verbose "Sourced ${tool_init}-${tool}.exp" 2
  506. } else {
  507.     if [file exists ${tool_init}.exp] then {
  508.     catch "source ${tool_init}.exp" error
  509.     if ![string match "" $error] then {
  510.         send_user "ERROR: errors in tool init file ${tool_init}.exp\n$error\n"
  511.         exit 1
  512.     }
  513.     verbose "Sourced ${tool_init}.exp" 2
  514.     } else {
  515.     catch "source ${tool_init}-${tool}.exp" error
  516.     if ![string match "" $error] then {
  517.         send_user "ERROR: errors in tool init file ${tool_init}-${tool}.exp\n$error\n"
  518.         exit 1
  519.     }
  520.     verbose "Sourced ${tool_init}-${tool}.exp" 2
  521.     } else {
  522.     error "There is no tool init file in $srcdir/config"
  523.     exit 1
  524.     }
  525. }    
  526.  
  527. #
  528. # trap some signals so we know whats happening. These replace the the previous
  529. # ones cause we've now loaded the library stuff
  530. #
  531. trap {
  532.     global exit_status
  533.     send_error "\nterminated\n"
  534.     log_summary
  535.     close_logs
  536.     cleanup
  537.     exit $exit_status
  538. } SIGTERM
  539. trap {
  540.     global exit_status
  541.     send_error "\ninterrupted by user\n"
  542.     log_summary
  543.     close_logs
  544.     cleanup
  545.     exit $exit_status
  546. } SIGINT
  547. trap {
  548.     global exit_status
  549.     send_error "\nsegmentation violation\n"
  550.     log_summary
  551.     close_logs
  552.     cleanup
  553.     exit $exit_status
  554. } SIGSEGV
  555. trap {
  556.     global exit_status
  557.     send_error "\nsigquit\n"
  558.     log_summary
  559.     close_logs
  560.     cleanup
  561.     exit $exit_status
  562. } SIGQUIT
  563.  
  564. #
  565. # main test execution loop
  566. #
  567. reset_vars
  568. foreach dir [lsort [getdirs $srcdir $tool*]] {
  569.     foreach test_name [lsort [find $dir *.exp]] {
  570.     set subdir [file dirname [string range ${test_name} [expr [string length $srcdir]+1] end]]
  571.     if [string match "" ${test_name}] then {
  572.         continue
  573.     }
  574.     # check to see if the range of tests is limited 
  575.     if ![string match "" $runtests] then {
  576.         if ![expr 0<=[lsearch $runtests [file tail ${test_name}]]] then {
  577.         continue
  578.         }
  579.     }
  580.     if ![string match "" $ignoretests] then {
  581.         if [expr 0<=[lsearch $ignoretests [file tail ${test_name}]]] then {
  582.         continue
  583.         }
  584.     }
  585.     clone_output "Running ${test_name} ..."
  586.     set prms_id    0
  587.     set bug_id    0
  588.     set test_result ""
  589.     if [file exists $test_name] then {
  590.         catch "source ${test_name}" test_result
  591.         if ![string match "" $test_result] then {
  592.                 if ![string match "0" $test_result] then {
  593.                     error "Got an error from ${test_name}\n$test_result"
  594.                     set test_result ""
  595.                     continue
  596.                 }
  597.         }
  598.     } else {
  599.         error "$test_name does not exist."
  600.     }
  601.     }    
  602. }
  603.  
  604. #
  605. # all done, cleanup
  606. #
  607. if {[info procs ${tool}_exit] != ""} then {
  608.     ${tool}_exit
  609. }
  610.  
  611. log_summary
  612. close_logs
  613. if $do_a_diff then {
  614.    if [diff_logs $psum_file] then {
  615.       if $mail_logs then {
  616.          mail_file $outdir/$tool.diff $mailing_list "Dejagnu Summary Diff"
  617.       }
  618.    } else {
  619.       if $mail_logs then {
  620.          catch "exec mail -s \"Dejagnu - No Differences Found\" $mailing_list < /dev/null"
  621.       }
  622.    }
  623. } else {
  624.    if $mail_logs then {
  625.       mail_file $outdir/$tool.sum $mailing_list "Dejagnu Summary Log"
  626.    }
  627. }
  628. cleanup
  629. exit $exit_status
  630.